#include<bits/stdc++.h>
using namespace std;
const int N=1502;
int n,m;
char arr[N][N];
bool visit[N][N];
const int dr[]={0,0,1,-1};
const int dc[]={1,-1,0,0};

int main(){
    while(cin>>n>>m){
        int r0,c0;
        for(int i=1;i<=n;i++){
            string s;
            cin>>s;
            for(int j=0;s[j]!='\0';j++){
                arr[i][j+1]=s[j];
                if(s[j]=='S'){
                    r0=i;c0=j+1;
                    arr[i][j+1]='.';
                }
            }
        }
        //bfs
        memset(visit,0,sizeof(visit));
        vector<int> points;
        queue<int> que;
        que.push(r0);que.push(c0);
        visit[r0][c0]=true;
        while(!que.empty())
        {
            int rc=que.front();
            que.pop();
            int cc=que.front();
            que.pop();
            for(int j=0;j<4;j++){
                int rn = rc+dr[j];
                int cn = cc+dc[j];
                if(rn<=0||rn>n) continue;
                if(cn<=0||cn>m) continue;
                if(visit[rn][cn]) continue;
                if(arr[rn][cn]=='#') continue;
                visit[rn][cn]=true;
                if(rn==1){
                    points.emplace_back(n);
                    points.emplace_back(cn);
                }
                else if(rn==n){
                    points.emplace_back(1);
                    points.emplace_back(cn);
                }
                if(cn==1){
                    points.emplace_back(rn);
                    points.emplace_back(m);
                }
                else if(cn==m){
                    points.emplace_back(rn);
                    points.emplace_back(1);
                }
                que.push(rn);
                que.push(cn);
                visit[rn][cn]=true;
            }
        }
        //
        bool suc=false;
        for(int j=0;j<points.size();j+=2){
            int rc=points[j];
            int cc=points[j+1];
            //cout<<rc<<' '<<cc<<endl;
            if(visit[rc][cc]){
                cout<<"Yes"<<endl;
                suc=true;
                break;
            }
        }
        if(!suc){
            cout<<"No"<<endl;
        }
    }
    return 0;
}